﻿#include "sortlogmodel.h"

#ifdef Q_CC_MSVC
#pragma execution_character_set("utf-8")
#endif


SortLogModel::SortLogModel(QObject* parent)
	: QSortFilterProxyModel{ parent }
{}




bool SortLogModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{	//获取model中实际的数据
	QString dataColumn1 = sourceModel()->index(source_row, col).data(Qt::DisplayRole).toString();
	//  QString dataColumn3 =  sourceModel()->index(source_row, 2, source_parent).data(Qt::DisplayRole).toString();

	switch (col)
	{
	case 2:
		if (dataColumn1.contains(filter))
		{
			return true;
		}
		return false;
	case 4:
		if (dataColumn1.contains(filter))
		{
			return true;
		}
		return false;
	case 3:
	{
		QDateTime date = QDateTime::fromString(dataColumn1, "yyyy/M/dd hh:mm:ss");
		if (date > date_1 && date < date_2)
			return true;	  }
	return false;

	default:
		break;
	}
	if (dataColumn1.contains(this->filterRegExp()))
	{
		return true;
	}
	// else if(dataColumn3.contains(this->filterRegExp()))
	{
		//     return true;
	}
	return false;
}
